package com.mgface.framework.springcloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.cloud.netflix.zuul.filters.discovery.PatternServiceRouteMapper;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@EnableZuulProxy
public class ZuulRegxAppliction {
    public static void main(String[] args) {
        SpringApplication.run(ZuulRegxAppliction.class,args);
    }

    /**
     *
     * 首先设置ms-provider-user模块的spring.application.name的值为ms-provider-user-v1
     * 然后启动访问以下地址
     * http://10.10.212.25:8501/v1/ms-provider-user/simple/1
     *
     * 其他的还是照常映射：http://10.10.212.25:8501/ms-feign-hystrix/movie/1
     * @return
     */
    @Bean
    public PatternServiceRouteMapper serviceRouteMapper() {
        /**
         *
         * 这意味着serviceId “myusers-v1”将被映射到路由“/v1/myusers/**”。
         * 如果servicePattern与serviceId不匹配，则使用默认行为（就是上面说的“其他的还是照常映射”）。
         */
        return new PatternServiceRouteMapper(
                "(?<name>^.+)-(?<version>v.+$)",
                "${version}/${name}");
    }

}

